﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NimLearning
{
    public class GameState
    {
        private int[] rows = new int[3];

        public int this[int i]
        {
            get
            {
                return rows[i];
            }
            set
            {
                rows[i] = value;
            }
        }

        public GameState(int first = 3, int second = 5, int third = 7)
        {
            rows[0] = first;
            rows[1] = second;
            rows[2] = third;
        }

        public bool IsDone()
        {
            return rows.Sum() == 0;
        }

        public List<GameState> GetPossibleOutcomes ()
        {
            List<GameState> outcomes = new List<GameState>();

            // loop though rows
            for (int row = 0; row < 3; row++)
            {
                // loop through possible values for each row
                for (int i = 0; i < rows[row]; i++)
                {
                    GameState outcome = new GameState();

                    outcome[0] = this[0];
                    outcome[1] = this[1];
                    outcome[2] = this[2];

                    outcome[row] = i;

                    outcomes.Add(outcome);
                }
            }

            return outcomes;
        }

        public void Print()
        {
            Console.WriteLine();
            for (int row = 0; row < 3; row++)
            {
                for (int i = 0; i < rows[row]; i++)
                {
                    Console.Write("x");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }

        public string Serialize()
        {
            return "" + rows[0] + rows[1] + rows[2];
        }
    }
}